package com.wang.controller;

import com.wang.pojo.User;
import com.wang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    UserService userServiceImpl ;

    @GetMapping("/")
    public String index(){
        return "index";
    }
    @GetMapping("/login")
    public String login(User user, Model model, HttpSession session){
        User login = userServiceImpl.login(user);
        if(login == null){
            model.addAttribute("msg", "用户名或密码错误");
            return "index";
        }
        else{
            session.setAttribute("loginUser", login);
            return "forward:/findAllBook";
        }
    }
}

